#===============================================
# Code written by Joe France (joeprogram.com)
# Released under code.google.com/p/video-scholar/
# with the MIT license (aka, the do-whatever-you-want-with-it license)
#===============================================

from AbstractGUI import AbstractGUI

class CompoundGUI( AbstractGUI ):
	'''
	Some GUIs are a single element,
	while others are composed of multiple GUI elements.
	
	CompoundGUI matches the interface of GUI,
	but uses a list of internal gui elements that it can pass
	its calls to, rather than referencing a single image.
	'''
	
	def __init__( self, origin = "left bottom" ):
		self.x = 0
		self.y = 0
		self.width = 0
		self.height = 0
		self.x_offset= 0
		self.y_offset = 0
		self.guis = []
		
	def set_coordinates( self, x = None, y = None ):
		'''
		Set the coordinates of the GUI
		Allows for None to be passed in for x or y
		in case you don't wish to change one of the variables
		'''

		if x is not None:
			self.x = x
		if y is not None:
			self.y = y
		
	def get_coordinates( self ):
		return (self.x, self.y)
		
	def set_dimensions( self, width = None, height = None ):
		if width is not None:
			self.width = width
		if height is not None:
			self.height = height
		
	def get_height( self ):
		return self.guis[0].get_height()
		
	def get_width( self ):
		return self.guis[0].get_width()
	
	def draw( self ):
		'''
		How to draw this GUI element upon the screen
		'''
		for gui in guis:
			gui.draw()
		
	def hit_test( self, x, y ):
		'''
		Returns true if the provided x and y coordinates intersect with this GUI
		
		First checks to see if the click is within the given bounds, then checks to see if any children guis were clicked.
		'''
		
		hit_box = x >= self.x and x <= self.x + self.width and y >= self.y and y <= self.y + self.height
		return hit_box or bool( filter(lambda gui: gui.hit_test(x,y), self.guis) )
		
	def mouse_over( self, x, y):
		'''
		Called if the mouse has entered the hit area of this gui
		'''		
		for gui in self.guis:
			gui.highlight()
		
	def mouse_out( self, x, y ):
		'''
		Called if the mouse has left the hit area of this gui
		'''
		for gui in self.guis:
			gui.dehighlight()
		
	def mouse_press( self, x, y, button, modifiers ):
		pass		
		
	def key_press( self, symbol, modifiers ):
		pass	